package osgi.classloader;

import java.lang.reflect.Method;
import java.util.Map;


public class OutServiceFactory {
	private static IClassLoaderService classLoaderService = null;
	
	public static Object invokeOutService(Map paraMap) {
		return invokeOutService(paraMap, null);
	}

	public static Object invokeOutService(Map paraMap, ClassLoader classLoader) {
		if (classLoaderService == null) {
			classLoaderService = new ClassLoaderService();
		}
		if(classLoader == null) {
			classLoader = classLoaderService.getClassLoader();
		}
		try {
			// 读取OSGi容器外的资源文件

			// 通过反射调用OSGi容器外的类方法
			Class clazz = classLoader.loadClass(
					"osgi.OSGIService");
			Object obj = clazz.newInstance();
			Method method = clazz.getMethod("invokeByOsgi", Map.class);
			Object result = method.invoke(obj, paraMap);
			return result;
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return null;
	}
}
